from django.db import models
from datetime import datetime


class PowerSystem(models.Model):
    sn_id = models.TextField(null=False, default="", verbose_name="sn")
    # PV1
    pv1_output_voltage = models.DecimalField(max_digits=10, decimal_places=3)
    pv1_output_current = models.DecimalField(max_digits=10, decimal_places=2)
    pv1_output_power = models.DecimalField(max_digits=10, decimal_places=3)
    pv1_generation = models.DecimalField(max_digits=10, decimal_places=3)

    # PV2
    pv2_output_voltage = models.DecimalField(max_digits=10, decimal_places=3)
    pv2_output_current = models.DecimalField(max_digits=10, decimal_places=3)
    pv2_output_power = models.DecimalField(max_digits=10, decimal_places=3)
    pv2_generation = models.DecimalField(max_digits=10, decimal_places=3)

    # 电池侧
    battery_capacity_voltage = models.DecimalField(max_digits=10, decimal_places=3)
    battery_side_voltage = models.DecimalField(max_digits=10, decimal_places=3)
    battery_side_current = models.DecimalField(max_digits=10, decimal_places=3)
    battery_side_inductor1_current = models.DecimalField(max_digits=10, decimal_places=3)
    battery_side_inductor2_current = models.DecimalField(max_digits=10, decimal_places=3)
    battery_side_charge_power = models.DecimalField(max_digits=10, decimal_places=3)
    battery_side_discharge_power = models.DecimalField(max_digits=10, decimal_places=3)
    battery_side_charge_quantity = models.DecimalField(max_digits=10, decimal_places=3)
    battery_side_discharge_quantity = models.DecimalField(max_digits=10, decimal_places=3)

    # 其他
    dc_component_output_current = models.DecimalField(max_digits=10, decimal_places=3)
    dc_component_load_voltage = models.DecimalField(max_digits=10, decimal_places=3)
    leakage_current = models.DecimalField(max_digits=10, decimal_places=3)
    zero_ground_voltage = models.DecimalField(max_digits=10, decimal_places=3)
    insulation_impedance_detection_voltage = models.DecimalField(max_digits=10, decimal_places=3)
    relay_midpoint_voltage_1 = models.DecimalField(max_digits=10, decimal_places=3)
    relay_midpoint_voltage_2 = models.DecimalField(max_digits=10, decimal_places=3)

    create_time = models.DateTimeField(null=True, blank=True, default=datetime.now, verbose_name="创建时间")

    update_time = models.DateTimeField(null=True, blank=True, default=datetime.now, verbose_name="更新时间")

    class Meta:
        app_label = "app"

    def __str__(self):
        return f"Power System Information {self.id}"
